package com.geekstudy.week11;


import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import redis.clients.jedis.Jedis;

@RunWith(BlockJUnit4ClassRunner.class)
public class RedisLockServiceVerify {

    @Test
    public void testLock() {

        UUIDTool uuidTool = new UUIDTool();
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        RedisLockService redisLockService = new RedisLockService(jedis);


        String lockName = "Demo2021";
        String version = uuidTool.uuid();
        boolean lockResult1 = redisLockService.lock(lockName, version);
        System.out.println(" lockResult1:" + lockResult1);

        boolean lockResult2 = redisLockService.lock(lockName, version);
        System.out.println(" lockResult2:" + lockResult2);

        boolean releaseResult1 = redisLockService.releaseLock(lockName, version);
        System.out.println(" releaseResult1:" + releaseResult1);

    }
}
